package com.xxw.yygh.user.controller.user;




import com.xxw.yygh.common.result.R;
import com.xxw.yygh.common.utils.JwtHelper;
import com.xxw.yygh.model.user.Patient;
import com.xxw.yygh.user.service.PatientService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 就诊人表(Patient)表控制层
 *
 * @author makejava
 * @since 2023-03-03 16:03:18
 */
@RestController
@RequestMapping("/user/userinfo/patient")
public class PatientController{

    @Resource
    private PatientService patientService;

    //新增
    @PostMapping("/save")
    public R save(@RequestBody Patient patient,@RequestHeader String token){
        Long userId = JwtHelper.getUserId(token);
        patient.setUserId(userId);
        patientService.save(patient);
        return R.ok();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        patientService.removeById(id);
        return R.ok();
    }

    //修改之回显
    @GetMapping("/detail/{id}")
    public R detail(@PathVariable Long id){
        Patient patient = patientService.detail(id);
        return R.ok().data("patient",patient);
    }

    //修改数据
    @PutMapping("/update")
    public R update(@RequestBody Patient patient){
        patientService.updateById(patient);
        return R.ok();
    }

    //查询
    @GetMapping("/all")
    public R findAll(@RequestHeader String token){

        List<Patient> list = patientService.findAll(token);
        return R.ok().data("list",list);
    }


    //远程调用
    @GetMapping("/{patientId}")
    public Patient getPatientById(@PathVariable(value = "patientId") Long patientId){
        return patientService.getById(patientId);
    }
}

